package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.food.dao.service.ApplicationService;
import com.food.dao.service.CollectService;
import com.food.dao.service.CourseService;
import com.food.dao.service.RecipeService;
import com.food.model.Application;
import com.food.model.Collect;
import com.food.model.Course;
import com.food.model.Member;
import com.food.model.Recipe;


@WebServlet("/member/MyCourse")
public class MyCourse extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ApplicationService applicationService = new ApplicationService();
		CourseService courseService = new CourseService();
		
		HttpSession session = request.getSession();
		Member member = (Member)session.getAttribute("user");
		
		Application application = new Application();
		application.setMbid(member.getMbid());
		List<Application> list = applicationService.findApplicationByMb(application);
		List<Course> coll = new ArrayList<Course>();
		for(Application ap:list){
			Course course = new Course();
			course.setCid(ap.getCid());
			course = courseService.findOneCourse(course);
			coll.add(course);
			
		}
		request.setAttribute("mbcourse", coll);
		RequestDispatcher rd = request
				.getRequestDispatcher("/member/mycourse.jsp");
		rd.forward(request, response);
		return;
	}

}
